package java基础;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class List删除BUG {
    public static void main(String[] args) {
        List<Integer> list=new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);
        Iterator<Integer> iterator = list.iterator();
        while (iterator.hasNext()){
            Integer next = iterator.next();
            if (next.intValue()==2){
                /**
                 * private void fastRemove(int index) {
                 *         modCount++;
                 *final void checkForComodification() {
                 *             if (modCount != expectedModCount)
                 *                 throw new ConcurrentModificationException();
                 *         }
                 *
                 * Exception in thread "main" java.util.ConcurrentModificationException
                 * 	at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:911)
                 * 	at java.util.ArrayList$Itr.next(ArrayList.java:861)
                 * 	at java基础.List删除BUG.main(List删除BUG.java:17)
                 */
                //iterator.remove();
                list.remove(next);
            }
        }
    }
}
